<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.bootcss.com/jquery/2.1.2/jquery.min.js"></script>
<script>
    $(function () {
      $("#subbtn").click(function () {

          var flag = true;

          $("#err_username").html('');
          $("#err_userpasswd").html('');

          var username = $("input[name='username']").val();
          var userpasswd = $("input[name='userpasswd']").val();

          if (username == ''){
              $("#err_username").html('名称不能为空');
           //   $("input[name='username']").focus();
              flag =  false;
          }
          if (userpasswd == ''){
              $("#err_userpasswd").html('密码不能为空');
             // $("input[name='userpasswd']").focus();
              flag =  false;
          }
          if (flag) {
              $.post('checklogin.php', {username: username, userpasswd: userpasswd}, function (data) {

                  if (data.code == 200) {
                      window.location.href = 'index.php';
                      return;
                  } else if (data.code == 501) {
                      $("#err_username").html(data.message);
                      return;
                  } else if (data.code == 502) {
                      $("#err_userpasswd").html(data.message);
                      return;
                  }

              }, 'json');
          }
      });
    });
    
    
</script>
<title>text</title>
    <style>
        #text{
            background:#e3e3e5;

        }
        #login{
            background:#ffffff;
            width: 300px;
            height:auto;
            overflow:hidden;
            margin:  0 auto;
            margin-top: 200px;
        }

        ipnut.in{
            width: 280px;
            height:30px;
            padding: 2px 10px;
            border:1px solid #e2e2e2;
        }
        a.subbtn{
            background: #829696;
            color: #333;
            text-decoration: none;
            border:1px solid #e2e2e2;
            width:120px;
            height:26px;
            line-height: 26px;
            overflow:hidden;
            display:block ;
            text-align: center;
            margin:  0 auto;
        }
        label.error{
            font-size:12px ;
            color:#f00;

        }

    </style>
</head>
<body id="text">
<?php

//if ($_GET['act'] == "loging") {
//    //表单数据提交， 接收 处理表单数据
//
//    echo $_POST['username'] . $_POST['userpasswd'] . '<br>';
//
//}
?>

<div id="login">
    <form name="login" action="text.php"method="post">

        <p>
        用户名:<input type="text" name="username"id="username"class="in">
            <label class="error" id="err_username"></label>
        </p>
        <p>
            密&nbsp;&nbsp;码:<input type="password"name="userpasswd" id="userpasswd"class="in">
            <label class="error" id="err_userpasswd"></label>

        </p>
            <a href="javascript:void(0);" class="subbtn" id="subbtn">登录</a>

</form>
</div>
</body>
</html>